package com.maycur.ctrip.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.maycur.ctrip.util.Constant;
import com.maycur.ice.ctrip.FlightOrderDto;
import com.maycur.ice.ctrip.FlightTicketDto;
import org.joda.time.DateTime;

import java.util.List;

/**
 * Created by JoeyXin on 6/29/16.
 */
public class FlightOrderInfoEntity {
    //基本信息
    @JsonProperty(value = "BasicInfo")
    private FlightOrderBasicInfo basicInfo;

    //订单配送信息
    @JsonProperty(value = "FlightDeliveryInfo")
    private FlightDeliveryInfo deliveryInfo;

    //航班信息
    @JsonProperty(value = "FlightInfo")
    private List<FlightTicketInfo> ticketInfos;

    //乘客信息
    @JsonProperty(value = "PassengerInfo")
    private List<FlightPassengerInfoEntity> passengerInfoEntities;

    //退票信息
    @JsonProperty(value = "RefundInfo")
    private List<FlightRefundInfoEntity> refundInfoEntities;

    public FlightOrderBasicInfo getBasicInfo() {
        return basicInfo;
    }

    public void setBasicInfo(FlightOrderBasicInfo basicInfo) {
        this.basicInfo = basicInfo;
    }

    public FlightDeliveryInfo getDeliveryInfo() {
        return deliveryInfo;
    }

    public void setDeliveryInfo(FlightDeliveryInfo deliveryInfo) {
        this.deliveryInfo = deliveryInfo;
    }

    public List<FlightTicketInfo> getTicketInfos() {
        return ticketInfos;
    }

    public void setTicketInfos(List<FlightTicketInfo> ticketInfos) {
        this.ticketInfos = ticketInfos;
    }

    public List<FlightPassengerInfoEntity> getPassengerInfoEntities() {
        return passengerInfoEntities;
    }

    public void setPassengerInfoEntities(List<FlightPassengerInfoEntity> passengerInfoEntities) {
        this.passengerInfoEntities = passengerInfoEntities;
    }

    public List<FlightRefundInfoEntity> getRefundInfoEntities() {
        return refundInfoEntities;
    }

    public void setRefundInfoEntities(List<FlightRefundInfoEntity> refundInfoEntities) {
        this.refundInfoEntities = refundInfoEntities;
    }

    public FlightOrderDto convertToOrderDto(){
        FlightOrderDto flightOrderDto = new FlightOrderDto();

        flightOrderDto.orderId = this.basicInfo.getOrderId();
        flightOrderDto.journeyNo = this.basicInfo.getJourneyNo();
        flightOrderDto.consumeAmount = this.basicInfo.getConsumeAmount().floatValue();
        //flightOrderDto.consumeCcy = TBD
        flightOrderDto.consumeDateTime = new DateTime(this.basicInfo.getOrderedAt()).toString(Constant.DATE_TIME_FORMAT);
        //flightOrderDto.consumeCity = TBD
        flightOrderDto.orderStatus = this.basicInfo.getOrderStatus();
        flightOrderDto.auditedStatus = this.basicInfo.getAuditedStatus();

        flightOrderDto.flightTicketDtoSeq = new FlightTicketDto[ticketInfos.size()];

        for(int i = 0; i< ticketInfos.size(); i++) {
            FlightTicketDto flightTicketDto = new FlightTicketDto();

            flightTicketDto.airLineName = ticketInfos.get(i).getAirLineName();
            flightTicketDto.totalAmount = ticketInfos.get(i).getTotalAmount().floatValue();
            flightTicketDto.flightNo = ticketInfos.get(i).getFlightNo();
            flightTicketDto.className = ticketInfos.get(i).getClassName();
            flightTicketDto.takeOffDateTime = new DateTime(ticketInfos.get(i).getTakeOffAt()).toString(Constant.DATE_TIME_FORMAT);
            flightTicketDto.arrivalDateTime = new DateTime(ticketInfos.get(i).getArrivalAt()).toString(Constant.DATE_TIME_FORMAT);
            flightTicketDto.departureCityName = ticketInfos.get(i).getDepartureCityName();
            flightTicketDto.arrivalCityName = ticketInfos.get(i).getArrivalCityName();

            flightOrderDto.flightTicketDtoSeq[i] = flightTicketDto;
        }

        return flightOrderDto;
    }
}
